﻿<%@ taglib prefix="s" uri="/struts-tags" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
		<title>插入图片</title>
		<style type="text/css">
			body, td, span, div, input {
				font-size: 12px;
				font-family: "宋体", "Courier New", Courier, monospace;
				margin: 0px;
			}
		</style>
		<script language="JavaScript">
		<!--
		window.isIE = (navigator.appName == "Microsoft Internet Explorer");
		if(window.isIE) {
			if(navigator.userAgent.indexOf("Opera")>-1) window.isIE = null;
		}
		else {
			if(navigator.userAgent.indexOf("Gecko")==-1) window.isIE = null;
		}
		function $(sID) {
			return document.getElementById(sID);
		}
		function adjustDialog(){
			var w = $("tabDialogSize").offsetWidth + 6;
			var h = $("tabDialogSize").offsetHeight + 25;
			window.dialogLeft = (screen.availWidth - w) / 2;
			window.dialogTop = (screen.availHeight - h) / 2;
		}
		window.onload = init;
		function init () {
			adjustDialog();
			//$("imgpath").select();
		}
		function LoadIMG(imgpath){
		    var editor = window.dialogArguments.EDiaryEditor;
		    var oRTE = editor.iframe.contentWindow;
		    var html = "<img src='" + imgpath + "'>";
			if(window.isIE) {
				try{
					oRTE.focus();
					var oRng = oRTE.document.selection.createRange();
					oRng.pasteHTML(html);
					oRng.collapse(false);
					oRng.select();
				}
				catch(e){}
			}
			else {
				editor.runCMD('insertHTML', html);
			}
			window.close();
		}
		function chk_imgpath () {
		  if($('radio1').checked==true){
			if($("imgpath").value == "http://" || $("imgpath").value == "") {
				window.close();
				return;
			}
			LoadIMG($("imgpath").value);
		  }else{
		    if($("file1").value == "") {
			   window.close();
			   return;
		    }
            if(!ifImage($("file1").value)){
                alert("仅支持JPG、BMP、GIF格式的图片上传！");
                return;
            }
		    $('form1').submit();
			$('divProcessing').style.display='';
		  }
		}
		document.onkeydown = function (el) {
			var event = window.event || el;
			if(event.keyCode == 13) {
			    chk_imgpath();
			}
		}

        function ifImage(obj){
            var hou = changeCodeLow(obj.substring(obj.length-3,obj.length));
            if(hou=="jpg" || hou=="jpeg" || hou=="gif" || hou=="bmp"){
                return true;
            }else{
                return false;
            }
        }

	function changeCodeLow(obj){
        var str = obj;
		var newstr="";
		for(var i = 0;i < str.length;i++){
			var a = str.charCodeAt(i);
			if(a>=65 && a<=90){
				a += parseInt(32);
			}
			newstr += String.fromCharCode(a);
		}
		return newstr;
}
		//-->
		</script>
	</head>
	<body>
    <table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0" id="tabDialogSize">
        <form name="form1" id="form1" method="post" action="<c:url value='/system/uploadImage.do'/>" enctype="multipart/form-data"
              target="myiframe">
            <tr>
                <td height="24" bgcolor="#DDE7EE" style="padding-left: 10px;">插入图片</td>
            </tr>
            <tr>
                <td height="40"><input type="radio" name="picurl" id="radio1" hidefocus="true"
                                       onClick="if(this.checked==true){$('imgpath').disabled='';$('file1').disabled='disabled';}">&nbsp;图片地址:
                    <input type="text" value="http://" style="border: 1px solid #999999; width: 235px;" id="imgpath"
                           name="imgpath" disabled="disabled"></td>
            </tr>
            <tr height="30">
                <td align="left" id="upid" width="400"><input type="radio" id="radio2" name="picurl" hidefocus="true"
                                                              onClick="if(this.checked==true){$('imgpath').disabled='disabled';$('file1').disabled='';}"
                                                              checked>&nbsp;上传图片:
                    <s:file name="file1" theme="simple" cssStyle="width:300px; border:#999999 1px solid"/>
                </td>
            </tr>
            <tr>
                <td style="padding: 10px;">&nbsp;</td>
            </tr>
            <tr>
                <td height="30" align="center" style="padding-bottom: 10px;"><a href="#" id="mysubmit"
                                                                                onClick=chk_imgpath()><img border="0"
                                                                                                           src="../images/dilog_bt_ok.gif"
                                                                                                           alt="确定"
                                                                                                           style="margin-right: 10px;"/></a><a
                        href="#" onClick="window.close();"><img border="0" src="../images/dilog_bt_cancel.gif"
                                                                alt="取消"/></a></td>
            </tr>
            <tr>
                <td bgcolor="#DDE7EE" height="5"></td>
            </tr>
        </form>
    </table>
<div id=divProcessing style="width:200px;height:30px;position:absolute;left:85px;top:75px;display:none">
<table border="0" cellpadding="0" cellspacing="1" bgcolor="#333333" width="100%" height="100%">
  <tr>
    <td bgcolor="#3A6EA5" align="center"><font color=#FFFFFF>图片上传中,请等待...</font></td>
  </tr>
</table>
</div>
<iframe src="" width="0" height="0" name="myiframe" id="myiframe" frameborder="0" scrolling="no"></iframe>
	</body>
</html>